package com.chouxiaozi.openfeigndemo.feignclient;

import com.chouxiaozi.openfeigndemo.vo.User;
import feign.*;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import feign.querymap.BeanQueryMapEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;

import javax.jws.soap.SOAPBinding;
import java.util.Map;


@FeignClient(name = "feignApiClient", url = "http://localhost:${server.port}/produce",configuration = BeanQueryMapEncoder.class)
public interface FeignApiInteferce{
//	class MultipartSupportConfig{
//		@Autowired
//		private ObjectFactory<HttpMessageConverters> messageConverters;
//
//		@Bean
//		public Encoder feignFormEncoder () {
//			return new SpringFormEncoder(new SpringEncoder(messageConverters));
//		}
//	}
    @Headers({"Content-Type: application/json"})
	@PostMapping("/post1")
	String post1(@RequestBody User user);

	@Headers({"Content-Type:application/json","Authorization:{authorization}"})
	@PostMapping("/post2")
    String post2(@RequestHeader(name = "authorization")String authorization,
				 @RequestBody User user);

	@Headers({"Content-Type:application/json","Authorization:{authorization}"})
	@PostMapping("/post3")
	String post3(@RequestHeader(name = "authorization")String authorization,
				 @RequestParam("gg") String gg,
				 @RequestBody User user);

	@Headers({"Content-Type:application/json","Authorization:{authorization}"})
	@GetMapping("/post4/{userId}?gg={gg}")
    String post4(@RequestHeader(name = "authorization")String authorization,
				 @PathVariable("userId") String userId,
				 @PathVariable("gg") String gg,
				 @RequestBody User user);

	@Headers({"Content-Type: application/x-www-form-urlencoded;charset=UTF-8"})
	@PostMapping("/post5")
	String post5(@RequestBody MultiValueMap<String, Object> user);

	@PostMapping(value = "/post5", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
	String post6(User user);

	//参数全都直接拼接到地址栏了
	@PostMapping("/post5")
	String post7(@RequestParam("name") String name, @RequestParam("sex") String sex);

	@GetMapping("/post6")
	String post8(@RequestParam("name") String name, @RequestParam("sex") String sex);

	@GetMapping(value = "/post6")
	String post9(@SpringQueryMap User user);
}